package cn.tedu.oa.announcement.controller;

import cn.tedu.oa.announcement.pojo.dto.AnnouncementQuery;
import cn.tedu.oa.announcement.pojo.dto.AnnouncementSaveParam;
import cn.tedu.oa.announcement.pojo.vo.AnnouncementVO;
import cn.tedu.oa.announcement.service.AnnouncementService;
import cn.tedu.oa.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/oa1/announcement")
public class AnnouncementController {
    @Autowired
    AnnouncementService announcementService;
    @GetMapping("select")
    public JsonResult select(AnnouncementQuery announcementQuery){
        log.debug("查询公告"+announcementQuery);
        List<AnnouncementVO> list = announcementService.select(announcementQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult save(AnnouncementSaveParam announcementSaveParam){
        log.debug("保存公告"+announcementSaveParam);
        announcementService.save(announcementSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete/{id}")
    public JsonResult delete( @PathVariable Integer id){
        log.debug("删除公告"+id);
        announcementService.delete(id);
        return JsonResult.ok();
    }
    @GetMapping("selectCount")
    public JsonResult selectCount(){
        log.debug("查询公告数量");
        Integer count = announcementService.selectCount();
        return JsonResult.ok(count);
    }

}
